<?php
namespace Site\Controller;
class MenuController extends CommonController {
    public function index() {
        $data = $this->getPageList(M('Menu'),array('sid'=>$this->sid),'sid desc,sort desc');
        $this->display();
    }

    public function add() {
        if(IS_POST) {
            D('Menu','Mysql')->addMenu(I('post.'));
            $this->success('菜单添加成功','/Menu');
        }
        $this->display();
    }

    public function update() {
        if(IS_POST) {
            D('Menu','Mysql')->updateMenu(I('post.'));
            $this->success('菜单修改成功','/Menu');
        }else {
            $id = I('get.id');
            verify($id,'isID','非法菜单ID');

            $menuInfo = M('Menu')->find($id);
            verify($menuInfo,'notEmpty','菜单不存在');

            if($menuInfo['sid'] !== $this->sid) {
                E('非法访问');
            }

            $this->assign('menuInfo',$menuInfo);
            $this->display();
        }
    }
}
?>
